<%@page contentType="text/html" import="java.util.Collection, Bean.*"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<%
if(session.getAttribute("un")==null){
    response.sendRedirect("indexAdmin.jsp?page=Admin&url=Login");
    out.println("You must be login..!");
}else{%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<script language="javascript" type="text/javascript" src="../script/validate.js"></script>
<script language="javascript">
       function kiemtra(){
            var curid = document.form1.txtcurid;
            var curname = document.form1.txtcurname;
            var curperiod = document.form1.txtperiod;
            var curfee = document.form1.txtfee;
            if( laChuoiRong(curid.value))
            {
                alert('Curriculum ID is not blank!');
                curid.focus();
                return false;
            }
            if( laChuoiRong(curname.value))
            {
                alert('Curriculum name is not blank!');
                curname.focus();
                return false;
            }
            if( laChuoiRong(curperiod.value))
            {
                alert('Curriculum period is not blank!');
                curperiod.focus();
                return false;
            }
            if( laChuoiRong(curfee.value))
            {
                alert('Curriculum fee is not blank!');
                curfee.focus();
                return false;
            }
            if(!laSoNguyen(curfee.value) )
            {
                alert('Curriculum fee is number!');
                curfee.focus();
                return false;
            }
            
       }
</script>   
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        
        <% 
        String curid="";String curname="";String period="";String fee="";
        if(session.getAttribute("curid")!=null){
            curid=session.getAttribute("curid").toString();
            curname=session.getAttribute("curname").toString();
            period=session.getAttribute("period").toString();
            fee=session.getAttribute("fee").toString();
            
        }
        
        %>
        <%
        CurriculumBean ojb=new CurriculumBean();
        Collection kq=ojb.getListCurriculum();
        request.setAttribute("st", kq);
        %>
        
        <form  action="../ControllCurriculum" name="form1" method="POST" onsubmit="return kiemtra()">
            <h3 align="center">Curriculum Management</h3>
            <table>
                
                <tr>
                    <td>CurID</td>
                    <td><input type="text" name="txtcurid" value="<%=curid%>" /><input type="hidden" name="txttemp" value="<%=curid%>" /></td>
                </tr>
                <tr>
                    <td>CurName</td>
                    <td><input type="text" name="txtcurname" value="<%=curname%>" /></td>
                </tr>
                <tr>
                    <td>Period</td>
                    <td><input type="text" name="txtperiod" value="<%=period%>" /></td>
                </tr>
                <tr>
                    <td>Fee</td>
                    <td><input type="text" name="txtfee" value="<%=fee%>" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="Insert" name="bt" />
                        <input type="submit" value="Update" name="bt" />
                        <input type="button" value="Reset" name="bt"  onclick="clear_fields()" />
                    </td>
                </tr>
            </table>
            
            
            <table border="1">
                <tr>
                    <th>CurID</th>
                    <th>CurName</th>
                    <th>Period</th>
                    <th>Fee</th>
                    <th colspan="2">Action</th>
                </tr>
                <pg:paging pageSize="10" url="indexAdmin.jsp?page=Admin&url=user"> 
                    <c:forEach items="${st}" var="s">
                        <pg:item> 
                            <tr>
                                <td><c:out value="${s.curid}" /></td>
                                <td>${s.curname}</td>
                                <td>${s.period}</td>
                                <td>${s.fee}</td>
                                
                                <c:url var="delete" value="../ControllCurriculum">
                                    <c:param name="bt" value="Delete" />
                                    <c:param name="curid" value="${s.curid}" />
                                    <c:param name="p" value="${param.pageNum}"/> 
                                </c:url>
                                <c:url var="edit" value="../ControllCurriculum">
                                    <c:param name="bt" value="Edit" />
                                    <c:param name="curid" value="${s.curid}" />
                                    <c:param name="curname" value="${s.curname}" />
                                    <c:param name="period" value="${s.period}" />
                                    <c:param name="fee" value="${s.fee}" />
                                    <c:param name="p" value="${param.pageNum}"/> 
                                </c:url>
                                <% if(session.getAttribute("permission")!=null){
                                    if(session.getAttribute("permission").equals("Academic")){%>
                                    <td><a href="${edit}">Edit</a></td>
                                <%    
                                    }
                                %>
                                <% 
                                    if(session.getAttribute("permission").equals("Admin")){%>
                                    <td><a href="${edit}">Edit</a></td>
                                    <td><a href="${delete}" onclick="return confirm('Do you really want to delete these records ?')">Delete</a></td>
                                <%    
                                    }
                                %>
                                <%}%>
                            </tr>
                        </pg:item> 
                    </c:forEach>
                     <pg:index>
                            <pg:page><%=thisPage%></pg:page>
                            <pg:firstPage>[First]</pg:firstPage>
                            <pg:lastPage>[Last]</pg:lastPage> 
                        </pg:index> 
                </pg:paging>
            </table>
        </form>
        
    </body>
</html>
<%}%>